from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings
from typing import Dict
import yaml
import os


class FnsaTelegramBotConfig(BaseModel):
    token: str

class AppConfig(BaseSettings):
    config_file_path: str = Field(..., env='CONFIG_FILE_PATH')
    etcd_host: str = Field(..., env='ETCD_HOST')
    etcd_port: int = Field(..., env='ETCD_PORT')
    
    class Config:
        env_file = '.env'

def load_config() -> FnsaTelegramBotConfig:
    app_config = AppConfig()
    
    with open(app_config.config_file_path, 'r') as file:
        config_dict = yaml.safe_load(file)
    
    fnsa_telegram_bot_config = config_dict.get('fnsa-telegram-bot')
    
    if fnsa_telegram_bot_config is None:
        raise ValueError("fnsa-telegram-bot configuration is missing")
    
    fnsa_telegram_bot_config = FnsaTelegramBotConfig(**fnsa_telegram_bot_config)
    
    return fnsa_telegram_bot_config, app_config.etcd_host, app_config.etcd_port

fnsa_telegram_bot_config, etcd_host, etcd_port = load_config()
